<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="删除标记" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入删除标记" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="版本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lockVersion">
              <a-input-number v-model="model.lockVersion" placeholder="请输入版本" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopId">
              <a-input v-model="model.shopId" placeholder="请输入店铺ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外卖信息ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tackoutId">
              <a-input v-model="model.tackoutId" placeholder="请输入外卖信息ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="日单量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderDay">
              <a-input v-model="model.orderDay" placeholder="请输入日单量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总单量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderTotal">
              <a-input v-model="model.orderTotal" placeholder="请输入总单量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="月单量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderMonthly">
              <a-input v-model="model.orderMonthly" placeholder="请输入月单量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="起送价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startFare">
              <a-input v-model="model.startFare" placeholder="请输入起送价格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="免费配送条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freeDistribution">
              <a-input v-model="model.freeDistribution" placeholder="请输入免费配送条件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大配送距离" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mxDistance">
              <a-input v-model="model.mxDistance" placeholder="请输入最大配送距离"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="免费配送距离" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freeDistance">
              <a-input v-model="model.freeDistance" placeholder="请输入免费配送距离"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺统一打包费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pack">
              <a-input v-model="model.pack" placeholder="请输入店铺统一打包费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单配送模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oderModel">
              <a-input v-model="model.oderModel" placeholder="请输入订单配送模式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预约单配送模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="appoModel">
              <a-input v-model="model.appoModel" placeholder="请输入预约单配送模式"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ShopTakeoutHisForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           delFlag: [
              { required: true, message: '请输入删除标记!'},
           ],
           lockVersion: [
              { required: true, message: '请输入版本!'},
           ],
           shopId: [
              { required: true, message: '请输入店铺ID!'},
           ],
           tackoutId: [
              { required: true, message: '请输入外卖信息ID!'},
           ],
           orderDay: [
              { required: true, message: '请输入日单量!'},
           ],
           orderTotal: [
              { required: true, message: '请输入总单量!'},
           ],
           orderMonthly: [
              { required: true, message: '请输入月单量!'},
           ],
           startFare: [
              { required: true, message: '请输入起送价格!'},
           ],
           freeDistribution: [
              { required: true, message: '请输入免费配送条件!'},
           ],
           mxDistance: [
              { required: true, message: '请输入最大配送距离!'},
           ],
           freeDistance: [
              { required: true, message: '请输入免费配送距离!'},
           ],
        },
        url: {
          add: "/shop/shopTakeoutHis/add",
          edit: "/shop/shopTakeoutHis/edit",
          queryById: "/shop/shopTakeoutHis/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>